#ifndef MSG_NODE_H 
#define MSG_NODE_H 

#include <cstdint>
#include <cstring>
#include <string>
#include <memory>
#include <utility>

#include <boost/asio.hpp>

#include "global.h"

class MsgNode
{
public:
    MsgNode(uint32_t total_len)
    :m_cur_len(0)
    ,m_total_len(total_len)
    ,m_data(new char[total_len + 1])
    {
        m_data[total_len] = '\0';
    }

    void Clear()
    {
        m_cur_len = 0;
        memset(m_data.get(), 0, m_total_len);
    }

    uint32_t m_cur_len;     // 当前已经处理的长度
    uint32_t m_total_len;   // 数据总长度
    std::unique_ptr<char[]> m_data;
};


class HeadNode: public MsgNode
{
public:
    HeadNode(uint32_t total_len, uint32_t msg_id)
    :MsgNode(total_len)
    ,m_msg_id(msg_id)
    {}

    uint32_t GetMsgId() const   { return m_msg_id; }
    uint32_t GetMsgLen() const  { return m_msg_len; }
    int GetHeatInfo();
    void Clear();
private:
    uint32_t m_msg_id;
    uint32_t m_msg_len;
};

class RecvNode: public MsgNode
{
public:
    RecvNode(uint32_t total_len, uint32_t msg_id)
    :MsgNode(total_len)
    ,m_msg_id(msg_id)
    {}
    
    uint32_t GetMsgId() const   { return m_msg_id; }
private:
    uint32_t m_msg_id;
};


//发送格式：消息ID + 消息长度 + 消息内容 ， 消息ID + 消息长度 = 消息头
class SendNode: public MsgNode
{
public:
    SendNode(const char* msg, uint32_t msg_len, uint32_t msg_id);

private:
    uint32_t m_msg_id;
};


#endif	/* MSG_NODE_H */
